package net;

import java.util.concurrent.atomic.AtomicBoolean;

public abstract class StoppableWorker implements Runnable {

    protected final AtomicBoolean stop = new AtomicBoolean(false);

    public void stop() {
        stop.set(true);
    }

    public void run() {
        while (!stop.get()) {
            work();
        }
    }

    protected abstract void work();
    
}
